package i5.modelman.merge.dependency;

import jpl.Atom;
import jpl.Compound;
import jpl.Term;
import jpl.Variable;

/**
 * It walks over the structure of the compound, ignoring all
 * composite and processing leaves.
 * @author xiang
 *
 */
public abstract class CompoundWalker {
	public void visit(Term t) {
		if (t.isAtom()) {
			visit((Atom) t);
		} else if (t.isVariable()) {
			visit((Variable) t);
		} else if (t.isCompound()) {
			visit((Compound) t);
		} else {
			visitGround(t);
		}
	}

	protected void visitGround(Term t) {
		// do nothing
	}

	protected abstract void visit(Variable var);

	protected abstract void visit(Atom atom);

	public void visit(Compound c) {
		for (int i = 1; i <= c.arity(); i++) {
			visit(c.arg(i));
		}
	}

}
